import {getLocalStorageJson} from "@/util/utilString";
import {addMark, setCollection} from "@/music";

export default {
    // 开启命名空间
    namespaced: true,
    getters: {
        getMusicList(state) {
            state.musicList.length = 0;
            let collectionList = getLocalStorageJson("collectionList");
            addMark(collectionList);
            state.musicList.push(...collectionList);
            return state.musicList;
        }
    },
    actions: {},
    mutations: {
        EMPTY(state) {
            state.musicList.length = 0;
        },
        ADD_MUSIC_COLLECTION(state, music) {
            setCollection(music, music.isCollection);
            state.musicList.length = 0;

            if (music.isCollection) {
                state.musicList.unshift(music);
            } else {
                state.musicList = state.musicList.filter((collection) => {
                    return music.id !== collection.id;
                })
            }
        },
        ADD_MUSIC_LIST_COLLECTION(state, data) {
            state.musicList.unshift(...data);
        },
    },
    state() {
        return {
            musicList: []
        }
    },
}
